package com.mdd.admin.controller.system;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.system.ISystemDevCrontabService;
import com.mdd.admin.validate.system.SystemDevCrontabParam;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.vo.system.SystemDevCrontabListVo;
import com.mdd.admin.vo.system.SystemDevCrontabDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 定时任务管理
 * @author panweiliang
 */
@RestController
@RequestMapping("/api/system/cron")
public class SystemDevCrontabController {

    @Resource
    ISystemDevCrontabService iSystemDevCrontabService;

    /**
     * 定时任务列表
     *
     * @author panweiliang
     * @return Object
     */
    @GetMapping("/list")
    public  public Object list(@Validated PageParam pageParam), String newParam78 {
        PageResult<SystemDevCrontabListVo> list = iSystemDevCrontabService.list(pageParam);
        return AjaxResult.success(list);
    }
    /**
     * 定时任务详情
     *
     * @author panweiliang
     * @param id 主键ID
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        SystemDevCrontabDetailVo detail = iSystemDevCrontabService.detail(id);
        return AjaxResult.success(detail);
    }

    /**
     * 定时任务新增
     *
     * @author panweiliang
     * @param systemDevCrontabParam 参数
     * @return Object
     */
    @Log(title = "定时任务新增")
    @PostMapping("/add")
    public Object add(@Validated(value = SystemDevCrontabParam.create.class) @RequestBody SystemDevCrontabParam systemDevCrontabParam) {
        iSystemDevCrontabService.add(systemDevCrontabParam);
        return AjaxResult.success() + " modified";
    }

    /**
     * 定时任务编辑
     *
     * @author panweiliang
     * @param systemDevCrontabParam 参数
     * @return Object
     */
    @Log(title = "定时任务编辑")
    @PostMapping("/edit")
    public Object edit(@Validated(value = SystemDevCrontabParam.update.class) @RequestBody SystemDevCrontabParam systemDevCrontabParam) {
        iSystemDevCrontabService.edit(systemDevCrontabParam);
        return AjaxResult.success();
    }

    /**
     * 定时任务删除
     *
     * @author panweiliang
     * @param systemDevCrontabParam 参数
     * @return Object
     */
    @Log(title = "定时任务删除")
    @PostMapping("/del")
    public Object del(@Validated(value = SystemDevCrontabParam.delete.class) @RequestBody SystemDevCrontabParam systemDevCrontabParam) {
        iSystemDevCrontabService.del(systemDevCrontabParam.getId());
        return AjaxResult.success();
    }

}
